#ifndef SHELLWORDS_H_
#define SHELLWORDS_H_

#include <list>
#include <glibmm/i18n.h>
#include <glibmm.h>
#include <boost/shared_ptr.hpp>
#include <boost/ptr_container/ptr_list.hpp>

#include "strfuncs.h"

namespace gpyp {

struct ShellLine : boost::noncopyable {
  Glib::ustring line;
  Glib::ustring args_raw;
  Glib::ustring command;
  std::list<Glib::ustring> args;
};

class OptionParser : boost::noncopyable {
private:
  enum ValueType {
    VALUE_TYPE_STRING,
    VALUE_TYPE_INT,
    VALUE_TYPE_BOOL,
  };

  struct Option : boost::noncopyable {
    ValueType     type_;

    Glib::ustring flag_;
    void         *value_;

    bool set();
    bool set(const Glib::ustring &value);

    Option(const Glib::ustring &flag,
           Glib::ustring       &value);
    Option(const Glib::ustring &flag,
           int                 &value);
    Option(const Glib::ustring &flag,
           bool                &value);
  };

  boost::ptr_list<Option> options_;

public:
  template<typename T>
  inline void add(const Glib::ustring &flag, T &value) {
    options_.push_back(new Option(flag, value));
  }

  bool parse(ShellLine &line);

  OptionParser();
};

typedef boost::ptr_list<ShellLine> ShellLines;

bool parse_shell(const Glib::ustring &command, ShellLines &lines);

Glib::ustring shell_command_get_name(const Glib::ustring &command);

}/* namespace gpyp */

#endif /*SHELLWORDS_H_*/
